﻿using MediatR;
using S.Common.Enums.PregnancyTest;
using S.PregnancyTest.Domain;
using S.PregnancyTest.Read.API.Application.Command;
using S.PregnancyTest.Read.API.Dto;

namespace S.PregnancyTest.Read.API.Application.CommandHandlers
{
    public class GetEarTagListHandler : IRequestHandler<GetEarTagListCommand, List<EarTagDto>>
    {

        private readonly MyDbContext dbContext;

        public GetEarTagListHandler(MyDbContext dbContext)
        {
            this.dbContext = dbContext;
        }

        public async Task<List<EarTagDto>> Handle(GetEarTagListCommand request, CancellationToken cancellationToken)
        {
            //获取到种母妊检信息
            var childList = dbContext.PregnancyTestModel.Where(x => x.SheepStatus == false && x.PregnancytestResult == (PregnancytestResultEnum)4).ToList();
            //将Id与耳号赋值
            List<EarTagDto> children = childList.Select(x => new EarTagDto
            {
                Value = x.PregnancytestId,
                Label = x.EarTag,
            }).ToList();

            return children;
        }
    }
}
